<?php
$app = Blyn::app()->getActiveApp();
$activeOperation = Blyn::app()->getActiveOperation();
$operationName = $activeOperation->getName();
?>

<link rel="stylesheet" type="text/css"
      href="<?php echo Yii::app()->request->baseUrl; ?>/css/bootstrap-datetimepicker.min.css" />
<script  type="text/javascript"
         src="<?php echo Yii::app()->request->baseUrl; ?>/js/bootstrap-datetimepicker.min.js"/>

<script type="text/javascript">
    $(document).ready(function() {
        $("#selectAll").click(function() {
            if ($(this).attr("checked") == "checked") {
                $(":checkbox").attr("checked", true);
            } else {
                $(":checkbox").attr("checked", false);
            }
        });

    });
</script> 

<script type="text/javascript">
    $(function() {
        $('.tree li:has(ul)').addClass('parent_li').find(' > span').attr('title', 'Collapse this branch');
        $('.tree li.parent_li > span').on('click', function(e) {
            var children = $(this).parent('li.parent_li').find(' > ul > li');
            if (children.is(":visible")) {
                children.hide('fast');
                $(this).attr('title', 'Expand this branch').find(' > i').addClass('icon-plus-sign').removeClass('icon-minus-sign');
            } else {
                children.show('fast');
                $(this).attr('title', 'Collapse this branch').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign');
            }
            e.stopPropagation();
        });
    });</script>
<script type="text/javascript">
    $(function() {
        $("#Event_Shop_CX").click(function() {
            document.getElementById("Event_Shop_CX_View").style.display = '';
            document.getElementById("Event_Clothes_CX_View").style.display = 'none';
        });
        $("#Event_Clothes_CX").click(function() {
            document.getElementById("Event_Shop_CX_View").style.display = 'none';
            document.getElementById("Event_Clothes_CX_View").style.display = '';
        });
    });</script>
<?php
if (!isset($title)) {
    $title = '功能列表';
}
?>
<legend><h4><?php echo $title; ?></h4></legend>

<fieldset>
    <table class="table table-hover">
        <thead>
            <tr>
                <th>
                    <input type="checkbox"  id="selectAll"> 
                </th>
                <th><?php echo '功能名称'; ?></th>
                <th><?php echo '功能类型'; ?></th>
                <th><?php echo '所属角色'; ?></th>
                <th><?php echo '功能说明'; ?></th>
                <th><?php echo '操作'; ?></th>
            </tr> 
        </thead>
        <tbody>
            <?php
            $eventCooker = new BAEventCooker();
            $roleCooker = new BARoleCooker();
            foreach ($userEventList as $id => $list) {
                $userEventData = $list->getItemsInArray();
                $eventId = $userEventData['eventId'];
                $roleId = $userEventData['roleId'];
                $allowModify = isset($userEventData['allowModify']) && $userEventData['allowModify'] == 'yes' ? TRUE : NULL;
                $allowDelete = isset($userEventData['allowDelete']) && $userEventData['allowDelete'] == 'yes' ? TRUE : NULL;
                $eventHome = isset($userEventData['eventHome']) ? $userEventData['eventHome'] : NULL;
                $eventHomeTitle = isset($userEventData['eventHomeTitle']) ? $userEventData['eventHomeTitle'] : '功能首页';
                if ($eventHome == NULL && $allowDelete == NULL && $allowDelete == NULL) {
                    continue;
                }
                $mobileTheme = isset($userEventData['mobileTheme']) ? $userEventData['mobileTheme'] : NULL;
                $role = new BRole($roleId);
                $event = $eventCooker->getEvent($eventId);
                $eventType = $eventCooker->getEventTypeByEvent($event);
                if ($event->getItem('alias') != NULL)
                    $eventName = $event->getItem('alias')->getValue();
                else
                    $eventName = $event->getItem('name')->getValue();
                //$changelessEventType = $eventType->getRootNode()->getChild('eventType.changeless');
                $eventTypeAlias = $eventCooker->getEventTypeAlias($eventType);
                if ($eventTypeAlias == NULL) {
                    $eventTypeAlias = $eventType->getValue();
                }
                $roleFullName = $role->getFullName();
                $roleAlias = BARoleCooker::getRoleAliasByFullName($roleFullName);
                ?>
                <tr>
                    <td><label class="checkbox">
                            <input type="checkbox" name="checkbox[]" value="<?php echo $event->getId(); ?>"> 
                        </label></td>
                    <td> <?php echo $eventName ?> </td>
                    <td> <?php echo $eventTypeAlias; ?> </td>       
                    <td> <?php echo $roleAlias; ?> </td>       
                    <td> <?php
                        $descItem = $event->getItem('description');
                        if ($descItem instanceof BTreeList) {
                            echo $event->getItem('description')->getValue();
                        } else {
                            echo Yii::t('site', 'no description');
                        }
                        ?> </td>    
                    <td>
                        <div class="row-fluid">                         
                            <?php
                            $actionString = '';

                            if (isset($userEventData['allowModify']) && $userEventData['allowModify'] == 'yes') {
                                //if (!$eventType->isChildOf($changelessEventType)) {
                                if ($actionString != '') {
                                    $actionString.= " | ";
                                }
                                $actionString.= $control->getAjaxLink(array('name' => '设置功能', 'id' => 'showAddEvent'), array(
                                    'cooker' => 'BAEvent@showAddEvent',
                                    'eventId' => $eventId
                                ));
                            }
                            if (isset($userEventData['allowDelete']) && $userEventData['allowDelete'] == 'yes') {
                                if ($actionString != '') {
                                    $actionString.= " | ";
                                }
                                $actionString.= $control->getAjaxLink(array('name' => '删除', 'id' => 'deleteEvent'), array(
                                    'cooker' => 'BAEvent@deleteEvent',
                                    'eventId' => $eventId
                                ));
                            }
                            if ($eventHome != NULL) {
                                if ($actionString != '') {
                                    $actionString.= " | ";
                                }
                                $actionString.= $control->getAjaxLink(array('name' => $eventHomeTitle, 'id' => 'showEventHome'), array(
                                    'cooker' => 'BAEvent@showEventHome',
                                    'eventId' => $eventId,
                                    'roleId' => $roleId,
                                    'eventHome' => $eventHome
                                ));
                            }
                            if ($mobileTheme != NULL) {
                                if ($actionString != '') {
                                    $actionString.= " | ";
                                }
                                $actionString.= $control->getLink(array('name' => '手机访问', 'id' => 'showEventHome'), array(
                                    'cooker' => 'BAEvent@showEventHome',
                                    'eventId' => $eventId,
                                    'roleId' => $roleId,
                                    'eventHome' => $eventHome,
                                    'htmlOptions' => array(
                                        'class' => '', 'target' => '_blank'),
                                ));
                            }
                            if ($actionString != '') {
                                echo $actionString;
                            }
                            //}
//                            echo " | ";
//                                    echo $control->getAjaxLink(array('name' => '帮助', 'id' => 'helpEvent'), array(
//                                        'cooker' => 'BAEvent@helpEvent',
//                                        'eventId' => $eventId
//                                    ));
//                            $wxControl = new BUIEventControl($eventName . 'Client');
//                            echo $wxControl->getLink(array('name' => '帮助', 'id' => 'helpEvent'), array(
//                                'cooker' => 'BAEvent@helpEvent',
//                                'eventId' => $eventId,
//                                'htmlOptions' => array(
//                                    'class' => '', 'target' => '_blank'),
//                                'theme' => 'mb_bootstrap'
//                            ));
                            ?> 
                        </div>                      
                    </td>
                </tr>
            <?php } ?>
        </tbody>
    </table>

    <div class="row-fluid">
        <?php
        $eventCooker = new BAEventCooker();
        $app = Blyn::app()->getActiveApp();

        if ($eventCooker->isUserAllowedAddEvent()) {
            if (method_exists($app, 'getAppEventTypeListData') && $app->getAppEventTypeListData() != NULL) {
                ?>
                <?php
                echo $control->getAjaxLink(array('name' => '新增功能', 'id' => 'showAddEvent'), array(
                    'eventId' => 0,
                    'cooker' => 'BAEvent@showAddEvent',
                    //'ajaxContainerId' => 'myModal',
                    'htmlOptions' => array(
                        //'enctype' => 'multipart/form-data',
                        'class' => 'btn'),
                        //'ajaxOptions' => array(
                        //'complete' => 'function(){$("#ajax-loaderdiv").hide();$("#myModal").modal("show");}')
                ));
                ?>
                <?php
                echo $control->getAjaxLink(array('name' => '删除功能', 'id' => 'deleteSelectedEvent'), array(
                    'cooker' => 'BAEvent@deleteEvent',
                    'htmlOptions' => array(
                        'class' => 'btn',
                    //'enctype' => 'multipart/form-data'
                )));
                ?>
                <?php
            }
        }
        $aControl = new BUIWXControl('aControl');
//                            $aControl = new BUIEventControl('aControl');
        echo $aControl->getLink(array('name' => '简洁界面', 'id' => 'simpleTheme'), array(
            'cooker' => 'BCafeBill@showManageBill',
            'theme' => 'a_bootstrap',
            'htmlOptions' => array('target' => '_blank', 'class' => 'btn btn-info')
        ));
        echo ' ';
        echo $aControl->getLink(array('name' => '帮助', 'id' => 'helpEvent'), array(
            'cooker' => 'BAEvent@helpEvent',
            //'eventId' => $eventId,
            'htmlOptions' => array(
                'class' => 'btn btn-success', 'target' => '_blank'),
            'theme' => 'mb_bootstrap'
        ));
        ?>
    </div>   
    <div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    </div>

    <div><input type="hidden" name="curPageNo" value="1"></div>

    <div class="pagination">  
        <ul>  
            <li class="active">
                <a href="javascript:void()">前一页</a>    </li>  
            <li class="active">
                <a href="javascript:void()">1</a>    </li>  
            <li class="active">
                <a href="javascript:void()">后一页</a>    </li>  
        </ul>  
    </div>


